package com.itheima.sh.service;

import com.itheima.sh.dao.UserMapper;
import com.itheima.sh.pojo.User;
import com.itheima.sh.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

public class RegisterMapperImpl {
    public boolean selectUser(User user) {
        SqlSession sqlSession=null;
        try {
             sqlSession = SqlSessionUtil.getSqlSession();
            UserMapper mapper = sqlSession.getMapper(UserMapper.class);

            User u =mapper.selectUserByUsername(user);

            if(u==null){
                mapper.addUser(user);
                return true;
            }else {
                return false;
            }
        } finally {
            if (sqlSession!=null) {
                sqlSession.close();
            }
        }
    }

}
